﻿Public Class ClassCompString
    'Comme cette classe doit être sérialisée il faut éviter les property readonly.
    'On va utiliser des fonctions à la place.
    Public CompData() As Byte

    Public Sub New()
        ReDim CompData(0)
    End Sub

    Public Function Longueur() As Integer
        Return CompData.Length
    End Function

    Public Sub SetValeur(ByVal Value As String)
        'Compression
        Dim mem As New IO.MemoryStream
        Dim gz As New System.IO.Compression.GZipStream(mem, IO.Compression.CompressionMode.Compress)
        Dim sw As New IO.StreamWriter(gz)
        For Each sLigne In Split(Value, vbCrLf)
            sw.WriteLine(sLigne)
        Next
        sw.Close()
        Me.CompData = mem.ToArray()
    End Sub

    Public Function GetValeur() As String
        'Decompression
        Dim mem2 As New IO.MemoryStream(Me.CompData)
        Dim gz As New System.IO.Compression.GZipStream(mem2, IO.Compression.CompressionMode.Decompress)
        Dim sr As New IO.StreamReader(gz)
        Dim Chaine As String = ""
        Do While Not sr.EndOfStream
            If Chaine <> "" Then Chaine &= vbCrLf
            Chaine &= sr.ReadLine
        Loop
        sr.Close()
        Return Chaine
    End Function
End Class
